<%- content_for :header_tags do %>
  <%= stylesheet_link_tag 'statistics', 'smoothness/jquery-ui-1.8rc3.custom.css', :plugin => 'redmine_backlogs' %>
  <%= javascript_include_tag 'jquery-1.4.2.min.js', 'jquery-ui-1.8rc3.custom.min.js', :plugin => 'redmine_backlogs' %>
<%- end %>

<script>
    var $j = jQuery.noConflict();
             
    $j(document).ready(function(){
        $j("#projects").accordion({ collapsible: true, header: 'h3'});
    });
</script>

<div id="projects">
    <% global = {} %>
    <% @projects.each do |project| %>
        <%
          stats = project.scrum_statistics
          scores = stats.scores
          errors = stats.errors('backlogs_')
          info = stats.info
          global = stats.merge(global, 'backlogs_')
        %>
        <h3><a href="#"><span class="score score_<%= stats.score %>"><%= stats.score %></span> <%= project.name %></a> </h3>
        <div>
            <% if !scores[:velocity_missing] %>
                <%= l(:label_sprint_velocity, { :velocity => info[:velocity], :sprints => info[:closed_sprints].length, :days => info[:average_days_per_sprint]}) %><br/>
            <% end %>
            <h4><%= l(:backlogs_product_backlog) %></h4>
            <%= link_to(l(:backlogs_product_backlog), { :controller => 'rb_queries', :action => 'show', :project_id => project }) %><br/>
            <% if info[:active_sprint] || info[:closed_sprints] %>
                <h4><%= l(:backlogs_sprints) %></h4>
                <% if info[:active_sprint] %>
                    <%= link_to(info[:active_sprint].name, {
                        :controller => 'rb_queries',
                        :action => 'show',
                        :project_id => project,
                        :sprint_id => info[:active_sprint].id }) %> (<%= l(:backlogs_active) %>)<br/>
                <% end %>
                <% if info[:closed_sprints] %>
                    <% info[:closed_sprints].each do |sprint| %>
                        <%= link_to(sprint.name, { :controller => 'rb_queries', :action => 'show', :project_id => project, :sprint_id => sprint.id }) %><br/>
                    <% end %>
                <% end %>
            <% end %>

            <% errors.each do |e| %>
                <ul>
                    <li><%= l(e) %></li>
                </ul>
            <% end %>
        </div>
    <% end %>
</div>
    <% if @projects.size > 0 %>
      <h3>Overall</h3>
      <table>
        <% global.each_pair do |e, n| %>
          <tr>
            <td><%= l(e) %></td>
            <td><b><%= (n * 100) / @projects.size %>%</b></td>
            <td><span class="score_<%= 10 - ((n * 10) / @projects.size) %>">&nbsp;&nbsp;</td>
          </tr>
        <% end %>
      </table>
    <% end %>
